/**
 * 路由权限控制
 *
 * meta noToken 设置为 true
 */
import config from '@/conf/index';
import router from './index';

const { title } = config;

router.beforeEach((to, form, next) => {
  document.title = to.meta.title ? `${title} - ${to.meta.title}` : title;

  const token = localStorage.getItem('token');

  if (!token && !to.matched.some((record) => record.meta.noRequiresAuth)) {
    document.title = `${title} - 登录`;

    next({
      path: '/login',
      // query: { redirect: to.fullPath }
    });
  }

  next();
});
